<!DOCTYPE html>
	<html lang="en">
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1.0">
		<title>Document</title>
		<link rel="stylesheet" type="text/css" href="../layui/css/layui.css">
		<link rel="stylesheet" type="text/css" href="../css/release.css">
	</head>
	<style type="text/css">
		#add{
			background: #81c8ff;
		    border: none;
		    color: #fff;
		    padding: 3px 10px;
		    border-radius: 5px;
		    outline: none;
		}
	</style>
	<body>
	<form action="">
		<div class="release">
			<div class="flex">
				<a href="javascript:history.back(-1)" class="underlining">取消</a>
				<input type="button" name=""  id="add"  value="发布">
			</div>
			<textarea name="tConte" placeholder="这一刻的想法..."></textarea>
			<!-- 上传照片 -->
			<div class="container">
		        <!--    照片添加    -->
		        <div class="z_photo">
		            <div class="z_file">
		                <input type="file" name="file" id="file" value="" accept="image/*" multiple/>

		            </div>

		        </div>
		        <div class="upload">
		        	
		        </div>
		        <!--遮罩层-->
		        <div class="z_mask">
		            <!--弹出框-->
		            <div class="z_alert">
		                <p>确定要删除这张图片吗？</p>
		                <p>
		                    <span class="z_cancel">取消</span>
		                    <span class="z_sure">确定</span>
		                </p>
		            </div>
		        </div>
		    </div>
		</div>
	</form>
		<script src="../js/jquery-3.3.1.js"></script>
		<script src="../layui/layui.all.js"></script>
		<script src="../js/release.js"></script>
	</body>
</html>
<script type="text/javascript">
/*var imgArr = [];
var arr=[];
function imgChange(obj1, obj2) {
    //获取点击的文本框
    var file = document.getElementById("file");
    //存放图片的父级元素
    var imgContainer = document.getElementsByClassName(obj1)[0];
    //获取的图片文件
    var fileList = file.files;
    //文本框的父级元素
    var input = document.getElementsByClassName(obj2)[0];
    
    //遍历获取到得图片文件
    for (var i = 0; i < fileList.length; i++) {
        var imgUrl = window.URL.createObjectURL(file.files[i]);
        imgArr.push(imgUrl);
        var img = document.createElement("img");
        img.setAttribute("src", imgArr[i]);
        var imgAdd = document.createElement("div");
        imgAdd.setAttribute("class", "z_addImg");
        imgAdd.appendChild(img);
        imgContainer.appendChild(imgAdd);
        arr.push($(file)[i].files[0]);
    };
    console.log(imgArr);
    imgRemove();
};

function imgRemove() {
    var imgList = document.getElementsByClassName("z_addImg");
    var mask = document.getElementsByClassName("z_mask")[0];
    var cancel = document.getElementsByClassName("z_cancel")[0];
    var sure = document.getElementsByClassName("z_sure")[0];
    for (var j = 0; j < imgList.length; j++) {
        imgList[j].index = j;
        imgList[j].onclick = function() {
            var t = this;
            mask.style.display = "block";
            cancel.onclick = function() {
                mask.style.display = "none";
            };
            sure.onclick = function() {
                mask.style.display = "none";
                t.style.display = "none";
            };

        }
    };
};*/
	var arr=[];
	$("#file").change(function() {
		//获取图片信息
		var fileLise = $(this)[0].files;
		var fileLength = fileLise.length;
		//然后循环 生成html 插入页面上 最后就赋值给img
		for (var i = 0; i < fileLength; i++) {
			var imgDiv = '<div class="imgDiv" style="width: 80px;height: 80px;display: inline-block;border: none;margin: 15px;"><img style="width: 100%;height: 100%" id="img' + fileLise[i].name + '"></div>';
			$(".upload").append(imgDiv);
			var imgName = document.getElementById("img" + fileLise[i].name);
			// var imgurl=window.URL.createObjectURL(fileLise[i]);
			if (fileLise && fileLise[i]) {
				var file = new FileReader();
				file.readAsDataURL(fileLise[i]);
				file.onload = function() {
					console.log(this);
					imgName.src = this.result;
				}
				arr.push($(this)[i].files[0]);
			}

			
		}
	});
$(document).on("click", ".imgDiv", function() {
		var index=$(this).index();
		arr.splice(index,1);
		$(this).remove();				
});
$("#add").click(function(){
	var formData= new FormData();
	for (var i = 0; i < arr.length; i++) {
		formData.append('mfile',arr[i]);
	}
	var account=localStorage.getItem("uCount"); 
	var tConte=$('textarea[name="tConte"]').val();
	var wd=localStorage.getItem("wd");
	var jd=localStorage.getItem("jd"); 
	formData.append('account',account);
	formData.append('tConte',tConte);
	formData.append('weidu',wd);
	formData.append('jindu',jd);
	$.ajax({
		url: "/meiyou/dongtai/adddongtai",
		data:formData,
        cache: false,//上传文件无需缓
		type: "Post",
            processData: false,//用于对data参数进行序列化处理 这里必须false
            contentType: false, //必须
            success: function (data) {
            	console.log(data);
            	if(data.code==100){
            		layer.msg(data.msg,{icon:6,time:1000},function(){
	        		window.location.href='../index.html';
	        	})
            		
            	}
            }
        })
});
	
</script>